import { defaultListRequestParams } from '@/config';
import api from '@/services/organization/user-management';

export type User = UserManagementApi.InfoResponse;
export type UserList = UserManagementApi.ListResponse;
export const getFilterList = async () => {
  const res = await api.getFilterList();
  return res.data;
};
export const getList = async (params: UserManagementApi.ListParams) => {
  const res = await api.getList<UserList>(params);
  const tableData: Requestor.TableFormatedData<UserList> = {
    data: res.listData,
    current: res.page + 1,
    pageSize: res.limit,
    total: res.count,
    success: res.success,
  };

  return tableData;
};
export const getAllList = async (params: { roleId?: string }) => {
  const requestParams: UserManagementApi.ListParams = {
    ...params,
    ...defaultListRequestParams,
    page: 0,
    limit: 500,
  };
  const res = await api.getList<UserList>(requestParams);
  return res.listData;
};
export const getInfo = async (params: UserManagementApi.InfoParams) => {
  const res = await api.getInfo<User>(params);
  return res.data;
};
export const create = async (params: UserManagementApi.CreateParams) => {
  const data = await api.create(params);
  return data;
};
export const update = async (params: UserManagementApi.UpdateParams) => {
  const data = await api.update(params);
  return data;
};
export const remove = async (params: UserManagementApi.DeleteParams) => {
  const data = await api.remove(params);
  return data;
};
export const updatePassword = async (params: UserManagementApi.PasswordParams) => {
  const data = await api.updatePassword(params);
  return data;
};
export const updateStatus = async (params: UserManagementApi.StatusParams) => {
  const data = await api.updateStatus(params);
  return data;
};
export default {
  getFilterList,
  getList,
  getAllList,
  getInfo,
  create,
  update,
  remove,
  updatePassword,
  updateStatus,
};
